package com.chencong.entity;

/**
 * @author chencong
 * @date 2020/12/15 下午1:32
 */

import com.chencong.service.FileService;
import com.chencong.service.PageService;
import com.chencong.service.ProviderService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *     {
 *       "id": 1,
 *       "isPay": 1,
 *       "isPayStr": "是",
 *       "money": 1000.0,
 *       "product": "购买一件商品",
 *       "providerId": 1,
 *       "providerName": "华为",
 *       "updateTime": "2020-10-02 22:20:48"
 *     }
 */

public class Bill {
    private int id;
    private int isPay;
    private String isPayStr;
    private double money;
    private String product;//产品描述
    private int providerId;
    private String providerName;
    private String updateTime;

    public Bill() {
    }

    public Bill(int id, int isPay, String isPayStr, double money, String product, int providerId, String providerName) {
        this.id = id;
        this.isPay = isPay;
        this.isPayStr = isPayStr;
        this.money = money;
        this.product = product;
        this.providerId = providerId;
        this.providerName = providerName;
    }

    public Bill(int id, int isPay, String isPayStr, double money, String product, int providerId, String providerName, String updateTime) {
        this.id = id;
        this.isPay = isPay;
        this.isPayStr = isPayStr;
        this.money = money;
        this.product = product;
        this.providerId = providerId;
        this.providerName = providerName;
        this.updateTime = updateTime;
    }

    /**
     * 获取
     * @return id
     */
    public int getId() {
        return id;
    }

    /**
     * 设置
     * @param id
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * 获取
     * @return isPay
     */
    public int getIsPay() {
        return isPay;
    }

    /**
     * 设置
     * @param isPay
     */
    public void setIsPay(int isPay) {
        this.isPay = isPay;
    }

    /**
     * 获取
     * @return isPayStr
     */
    public String getIsPayStr() {
        return isPay==0?"未付款":"已付款";
    }

    /**
     * 设置
     * @param
     */
    public void setIsPayStr() {
        this.isPayStr = this.isPay==0?"未付款":"已付款";
    }

    /**
     * 获取
     * @return money
     */
    public double getMoney() {
        return money;
    }

    /**
     * 设置
     * @param money
     */
    public void setMoney(double money) {
        this.money = money;
    }

    /**
     * 获取
     * @return product
     */
    public String getProduct() {
        return product;
    }

    /**
     * 设置
     * @param product
     */
    public void setProduct(String product) {
        this.product = product;
    }

    /**
     * 获取
     * @return providerId
     */
    public int getProviderId() {
        return providerId;
    }

    /**
     * 设置
     * @param providerId
     */
    public void setProviderId(int providerId) {
        this.providerId = providerId;
    }

    /**
     * 获取
     * @return providerName
     */
    public String getProviderName() {
        return providerName;
    }

    /**
     * 设置
     * @param
     */
    public void setProviderName(String providerName)  {
       this.providerName=providerName;
    }
    public void setProviderName() throws Exception {
        List<Provider> providers = new ProviderService().loadProvider();
        Provider provider1 = providers.stream().filter(provider -> provider.getId() == this.getProviderId()).findFirst().get();
        this.providerName = provider1.getName();
    }


    /**
     * 获取
     * @return updateTime
     */
    public String getUpdateTime() {
        return updateTime;
    }

    /**
     * 设置
     * @param
     */
    public void setUpdateTime(String updateTime) {
        this.updateTime= updateTime;
    }
    public void setUpdateTime() {
        this.updateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    public String toString() {
        return "Bill{id = " + id + ", isPay = " + isPay + ", isPayStr = " + isPayStr + ", money = " + money + ", product = " + product + ", providerId = " + providerId + ", providerName = " + providerName + ", updateTime = " + updateTime + "}";
    }
}
